package com.ly.hotel.spainterface.pp.utils;

import android.os.Handler;
import android.os.Message;

import com.ly.hotel.webagent.HttpRequest;


/**
 * Created by mo on 2018/5/31.
 */

public class CommonHttpUtils {

    public static void getResource(final String URL, final String request, final Handler handler, final int judeNum) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String str = null;
                if (request != null) {
                    str = new String(request.replace(" ", "%20"));
                }
                String sendRes = HttpRequest.sendGet(URL, str);
                if (sendRes.equals("ERROR")) {
                    Message message = new Message();
                    message.what = 2;
                    message.arg2 = judeNum;
                    handler.sendMessage(message);
                } else {
                    Message message = new Message();
                    message.what = 1;
                    message.arg1 = judeNum;
                    message.obj = sendRes;
                    handler.sendMessage(message);
                }
            }
        }).start();
    }

    public static void postJsonResource(final String URL, final String request, final Handler handler, final int judeNum) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                String str = null;
                if (request != null) {
                    str = new String(request.replace(" ", "%20"));
                }
                String sendRes = HttpRequest.sendPost(URL, str);
                if (sendRes.equals("ERROR")) {
                    Message message = new Message();
                    message.what = 2;
                    message.arg2 = judeNum;
                    handler.sendMessage(message);
                } else {
                    Message message = new Message();
                    message.what = 1;
                    message.arg1 = judeNum;
                    message.obj = sendRes;
                    handler.sendMessage(message);
                }
            }
        }).start();
    }
}
